package com.geek.javase.ch07.strings;

/*
 *@author wangpeng
 *2025/10/15 16:09
 *@description TODO
 */
//练习1：用StringBuilder把数组拼接成一个字符串
//举例：int[] arr = {1,2,3};  结果：[1, 2, 3]

public class StringBuilderDemo3 {
    static int[] arr = {1,2,3};
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if(i == 0){
                sb.append("[");
            }
            sb.append(arr[i]);
            if(i != arr.length - 1){
                sb.append(",");
            }
            if(i == arr.length - 1){
                sb.append("]");
            }
        }
        System.out.println(sb);
    }
}
